<template>
	<view class="works-item">
		<!-- 作业左侧图片区域 -->
		<view class="works-item-left">
			<radio :checked="works.goods_state" color="#c00000" v-if="showRadio" @click="radioClickHandler"></radio>
			<image :src="works.goods_small_logo || defaultPic" class="works-pic"></image>
		</view>
		<!-- 作业右侧信息区域 -->
		<view class="works-item-right">
			<!-- 作业标题 -->
			<view class="works-name">
				{{works.goods_name}}
			</view>
			<!-- 奖励 -->
			<view class="favi" v-if="showFlower">
			  <image src="../../static/flower.png" mode=""></image>
			</view>
			<view class="works-info-box" v-if="showDate">
				<!-- 作业截止日期 -->
				<view class="works-date">日期</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"my-works",
		// 定义 props 属性，用来接收外界传递到当前组件的数据
		props: {
			// 商品的信息对象
			works: {
				type: Object,
				defaul: {},
			},
			// 是否展示图片左侧的 radio
			showRadio: {
				type: Boolean,
				// 如果外界没有指定 show-radio 属性的值，则默认不展示 radio 组件
				default: false
			},
			showFlower: {
				type: Boolean,
				default: false,
			},
			showDate: {
				type: Boolean,
				default: true,
			}
		},
		data() {
			return {
				// 默认的空图片
				defaultPic: '/static/work.png'
			}
		},
		methods: {
			// radio 组件的点击事件处理函数
			radioClickHandler() {
				// 通过 this.$emit() 触发外界通过 @ 绑定的 radio-change 事件，
				// 同时把作业的 Id 和 勾选状态 作为参数传递给 radio-change 事件处理函数
				this.$emit('radio-change', {
					// 作业 id
					goods_id: this.works.goods_id,
					// 作业最新的勾选状态
					goods_state: !this.works.goods_state
				})
			}
		}
	}
</script>

<style lang="scss">
	.works-item {
		// 让 works-item 项占满整个屏幕的宽度
		width: 750rpx;
		box-sizing: border-box;
		display: flex;
		padding: 10px 5px;
		border-bottom: 1px solid #f0f0f0;

		.works-item-left {
			margin-right: 5px;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.works-pic {
				width: 100px;
				height: 100px;
				display: block;
			}
		}

		.works-item-right {
			display: flex;
			flex: 1;
			flex-direction: column;
			justify-content: space-between;

			.works-name {
				font-size: 13px;
			}
			
			.works-info-box {
				display: flex;
				align-items: center;
				justify-content: space-between;
			}
			
			.favi image {
				width: 50rpx;
				height: 50rpx;
			}

			.works-date {
				font-size: 16px;
				color: #c00000;
			}
		}
	}
</style>
